package com.micro.modual.service.impl;

import com.micro.common.MicroConstant;
import com.micro.common.MicroResponseCode;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.modual.entity.AdvertLaunch;
import com.micro.modual.extension.AdvertLaunchExtension;
import com.micro.modual.mapper.AdvertLaunchMapper;
import com.micro.modual.model.bo.advertlaunch.AdvertLaunchBO;
import com.micro.modual.service.AdvertLaunchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
*  <h1>广告基础表  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("advertLaunchService")
public class AdvertLaunchServiceImpl extends AbstractBasicsServiceImpl<AdvertLaunch,Long> implements AdvertLaunchService {

    @Autowired
    private AdvertLaunchMapper advertLaunchMapper;

    /**
     * <h2>新增广告基础表详情</h2>
     * @param advertLaunchBO {@link AdvertLaunchBO} 广告基础表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addAdvertLaunch(AdvertLaunchBO advertLaunchBO) {
        AdvertLaunch advertLaunch = AdvertLaunchExtension.converAddAdvertLaunch(advertLaunchBO);
        advertLaunchMapper.insertSelective(advertLaunch);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改广告基础表详情</h2>
     * @param advertLaunchBO  {@link AdvertLaunchBO} 广告基础表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editAdvertLaunch(AdvertLaunchBO advertLaunchBO) {
        AdvertLaunch advertLaunch = AdvertLaunchExtension.converEditAdvertLaunch(advertLaunchBO);
        advertLaunchMapper.updateByPrimaryKeySelective(advertLaunch);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除广告基础表信息</h2>
     * @param id  广告基础表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deleteAdvertLaunch(Long id) {
        AdvertLaunch advertLaunch = advertLaunchMapper.selectByPrimaryKey(id);
        if(advertLaunch.getAdvertStatus().equals(MicroConstant.StatusExecution.IN_PROGRESS)){
            throw new BizException(MicroResponseCode.HAS_IN_PROGRESS_ADVERT_NOT_ALLOW_DELETE.getResponseCode(),MicroResponseCode.HAS_IN_PROGRESS_ADVERT_NOT_ALLOW_DELETE.getResponseMessage());
        }
        advertLaunchMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

}
